package cn.yj.frame.event;

import cn.yj.frame.netty.NettyServer;
import cn.yj.register.RegisterConfig;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.context.ApplicationListener;

/**
 * 服务启动失败 移除注册
 * @author 永健
 * @since 2022-01-19 09:57
 */
public class ApplicationStartFailListener implements ApplicationListener<ApplicationFailedEvent> {

    @Override
    public void onApplicationEvent(ApplicationFailedEvent applicationFailedEvent) {
        // 服务启动失败,移除注册中心的服务
        RegisterConfig.logout();

        // 关闭netty
        NettyServer.closeServer();
    }
}
